﻿namespace EFMLEditor.Internal.Validating.Attributes
{
    using System.Reflection;

    public class LengthAttribute : ValidatingAttribute
    {
        private readonly int min;

        private readonly int max;

        public LengthAttribute(int min, int max)
        {
            this.min = min;
            this.max = max;
        }

        #region Overrides of ValidatingAttribute

        public override bool Do(object input, ParameterInfo parameter)
        {
            var l = input is string ? input.ToString().Length : (int)input;
            if(l >= min && l <= max)
            {
                
                return true;
            }
            this.Message = parameter.Name + " must be greater than " + this.min + " and less than " + this.max;
            return false;
        }

        #endregion
    }
}